package builderPattern.effectiveCode;

import lombok.Data;

/**
 * @author： pang-yun
 * @date： 2022-01-10 11:57
 * 功能目的 ：用于
 */
@Data
public class Person {
    /**
     * 必选参数
     */
    private final int id;
    private final String name;
    private final int age;
    private final String sex;
    private final String desc;


    public Person(Builder builder) {
        this.id = builder.id;
        this.name = builder.name;
        this.age = builder.age;
        this.sex = builder.sex;
        this.desc = builder.desc;
    }

    public static class Builder{
        private final int id;
        private final String name;
        private  int age;
        private  String sex;
        private  String desc;

        public Builder(int id, String name) {
            this.id = id;
            this.name = name;
        }

        public Builder age(int age){
            this.age=age;
            return this;
        }

        public Builder sex(String sex){
            this.sex=sex;
            return this;
        }

        public Builder desc(String desc){
            this.desc = desc;
            return this;
        }

        public Person build(){
            return new Person(this);
        }
    }
}
